package com.ncr.travel.appmgr.client.ui;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * @author ng185038
 * 
 */
public class ErrorDialog extends DialogBox {

	private Button okBtn;

	/*private FlowPanel mainPanel = new FlowPanel();*/
	private VerticalPanel mainPanel = new VerticalPanel();

	private ErrorDialog dialog;

	public ErrorDialog(String errorText) {
		super();
		okBtn = new Button("Ok");
		okBtn.setHeight("50px");
		okBtn.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				dialog.hide();
				dialog = null;
			}
		});
		
		/*mainPanel.setStyleName("errorDialog");*/
		
		Label lblError = new Label(errorText);
		ScrollPanel errorScrollPanel = new ScrollPanel();
		errorScrollPanel.setWidget(lblError);

		mainPanel.add(errorScrollPanel);
		mainPanel.add(new HTML("<HR>"));
		mainPanel.add(okBtn);
		setWidget(mainPanel);
		setAutoHideEnabled(false);
		setAnimationEnabled(true);
		setGlassEnabled(true);
		setText("Error");
		dialog = this;
		okBtn.setFocus(true);
		/*okBtn = new Button("Ok");
		okBtn.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				dialog.hide();
				dialog = null;
			}
		});
		FlexTable buttonsPnl = new FlexTable();
		buttonsPnl.setCellSpacing(10);
		buttonsPnl.setWidget(0, 0, okBtn);

		VerticalPanel buttonsMainPnl = new VerticalPanel();
		buttonsMainPnl.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
		buttonsMainPnl.setWidth("100%");
		buttonsMainPnl.add(new HTML("<HR>"));
		buttonsMainPnl.add(buttonsPnl);

		VerticalPanel dialogVPanel = new VerticalPanel();
		dialogVPanel.addStyleName("dialogVPanel");
		dialogVPanel.add(new Label(errorText));
		dialogVPanel.add(new HTML("<BR>"));
		ScrollPanel sp = new ScrollPanel();
		sp.setSize("400px", "75px");
		sp.setWidget(dialogVPanel);

		mainPanel.add(sp);
		mainPanel.add(buttonsMainPnl);
		setWidget(mainPanel);
		setAutoHideEnabled(false);
		setAnimationEnabled(true);
		setGlassEnabled(true);
		setText("Error");
		dialog = this;
		okBtn.setFocus(true);*/
	}

	public void showView() {
		center();
	}

	public Button getYesBtn() {
		return okBtn;
	}

	public void setYesBtn(Button yesBtn) {
		this.okBtn = yesBtn;
	}

}